/*!
 @header LcbCache.h
 @abstract 缓存类
 @author 刘成彬
 @version 1.0 2016/05/23 Creation
 */

#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/*!
 @class
 @abstract 实体基类。
 */
@interface LcbCache : NSObject
+ (instancetype)sharedCache;
+ (instancetype)sharedCacheWithName:(NSString*)cachename;
#pragma mark - Access Methods

/*!
 @method
 @abstract  Returns a boolean value that indicates whether a given key is in cache.
 This method may blocks the calling thread until file read finished.
 @code
 [LcbCache sharedCache］containsObjectForKey:@""];
 @endcode
 @param key A string identifying the value. If nil, just return NO.
 @result Whether the key is in cache.
 */
- (BOOL)containsObjectForKey:(NSString *)key;
/*!
 @method
 @abstract Returns a boolean value with the block that indicates whether a given key is in cache.
 This method returns immediately and invoke the passed block in background queue
 when the operation finished.
 @code
 [LcbCache sharedCache］containsObjectForKey:@"" withBlock:block];
 @endcode
 @param key   A string identifying the value. If nil, just return NO.
 @param block A block which will be invoked in background queue when finished.
 @result Whether the key is in cache.
 */

- (void)containsObjectForKey:(NSString *)key withBlock:(nullable void(^)(NSString *key, BOOL contains))block;
/*!
 @method
 @abstract Returns the value associated with a given key.
 This method may blocks the calling thread until file read finished.
 @code
 [LcbCache sharedCache］objectForKey:@""];
 @endcode
 @param key A string identifying the value. If nil, just return nil.
 @return The value associated with key, or nil if no value is associated with key.
 */
- (nullable id<NSCoding>)objectForKey:(NSString *)key;
/*!
 @method
 @abstract Returns the value associated with a given key.
 This method returns immediately and invoke the passed block in background queue
 when the operation finished.
 @code
[LcbCache sharedCache］objectForKey:@"" withBlock:block];
 @endcode
 @param key A string identifying the value. If nil, just return nil.
 @param block A block which will be invoked in background queue when finished.
 */

- (void)objectForKey:(NSString *)key withBlock:(nullable void(^)(NSString *key, id<NSCoding> object))block;
/*!
 @method
 @abstract  Sets the value of the specified key in the cache.
 This method may blocks the calling thread until file write finished.
 @code
 [LcbCache sharedCache］setObject:@"" forKey:@""];
 @endcode
 @param object The object to be stored in the cache. If nil, it calls `removeObjectForKey:`.
 @param key    The key with which to associate the value. If nil, this method has no effect.
 */
- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key;
/*!
 @method
 @abstract Sets the value of the specified key in the cache.
 This method returns immediately and invoke the passed block in background queue
 when the operation finished.
 @code
 [LcbCache sharedCache］setObject:@"" forKey:@"" withBlock:block];
 @endcode
 @param object The object to be stored in the cache. If nil, it calls `removeObjectForKey:`.
 @param block  A block which will be invoked in background queue when finished.
 */
- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key withBlock:(nullable void(^)(void))block;
/*!
 @method
 @abstract  Removes the value of the specified key in the cache.
 This method may blocks the calling thread until file delete finished.
 @code
 [LcbCache sharedCache］removeObjectForKey:@"" ];
 @endcode
 @param key The key identifying the value to be removed. If nil, this method has no effect.
 */
- (void)removeObjectForKey:(NSString *)key;
/*!
 @method
 @abstract Removes the value of the specified key in the cache.
 This method returns immediately and invoke the passed block in background queue
 when the operation finished.
 @code
 [LcbCache sharedCache］removeObjectForKey:@"" withBlock:block];
 @endcode
 @param key The key identifying the value to be removed. If nil, this method has no effect.
 @param block  A block which will be invoked in background queue when finished.
 */
- (void)removeObjectForKey:(NSString *)key withBlock:(nullable void(^)(NSString *key))block;
/*!
 @method
 @abstract Empties the cache.
 This method may blocks the calling thread until file delete finished.
 */
- (void)removeAllObjects;
/*!
 @method
 @abstract Empties the cache.
 This method returns immediately and invoke the passed block in background queue
 when the operation finished.
 @code
 [[LcbCache sharedCache］ removeAllObjectsWithBlock:block];
 @endcode
 @param block  A block which will be invoked in background queue when finished.
 */
- (void)removeAllObjectsWithBlock:(void(^)(void))block;
/*!
 @method
 @abstract Empties the cache with block.
 This method returns immediately and executes the clear operation with block in background.
 @code
 [LcbCache sharedCache］removeAllObjectsWithProgressBlock:@"" endBlock:end];
 @endcode
 @param progress This block will be invoked during removing, pass nil to ignore.
 @param end      This block will be invoked at the end, pass nil to ignore.
 */
- (void)removeAllObjectsWithProgressBlock:(nullable void(^)(int removedCount, int totalCount))progress
                                 endBlock:(nullable void(^)(BOOL error))end;

@end

NS_ASSUME_NONNULL_END
